package com.everydayflash.fp10{
	import flash.filters.ShaderFilter;	
	import flash.utils.ByteArray;	
	import flash.display.Shader;	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageQuality;
	import flash.display.StageScaleMode;
	import flash.events.Event;		

	/**
	 * @author bartekd
	 */
	public class GreyScaleFilter extends Sprite {

		private var rect:Sprite;
		
		[Embed (source="greyscale.pbj", mimeType="application/octet-stream")]
		private var GreyScaleShaderBA:Class;
		
		public function GreyScaleFilter() {
			stage.quality = StageQuality.LOW;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			stage.showDefaultContextMenu = false;
			stage.stageFocusRect = false;
			
			rect = new Sprite();
			rect.graphics.beginFill(0x00ff00);
			rect.graphics.drawRect(-100, -100, 200, 200);
			rect.graphics.endFill();
			rect.x = 250;
			rect.y = 250;
			addChild(rect);
			
			var shader:Shader = new Shader(new GreyScaleShaderBA() as ByteArray);
//			shader.data.amount.value = [100];
			var filter:ShaderFilter = new ShaderFilter(shader);
			
			rect.filters = [filter];
			
			addEventListener(Event.ENTER_FRAME, render);
		}
		
		private function render(event:Event):void {
			rect.rotationY += 10;
		}
	}
}
